package com.hualan.sfzy.service.course.serviceimpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.entity.course.CourseVideo;
import com.hualan.sfzy.mapper.course.CourseVideoMapper;
import com.hualan.sfzy.service.course.CourseVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CourseVideoServiceImpl implements CourseVideoService {
    @Autowired
    private CourseVideoMapper courseVideoMapper;
    @Override
    public int add(CourseVideo courseVideo) {
        return courseVideoMapper.insert(courseVideo);
    }

    @Override
    public int remove(Integer id) {
        return courseVideoMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return courseVideoMapper.deleteBatch(ids);
    }

    @Override
    public int edit(CourseVideo courseVideo) {
        return courseVideoMapper.update(courseVideo);
    }

    @Override
    public CourseVideo findById(Integer id) {
        return courseVideoMapper.selectById(id);
    }

    @Override
    public List<CourseVideo> find() {
        return courseVideoMapper.select(null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, CourseVideo courseVideo) {
        PageHelper.startPage(pageNum, pageSize);
        List<CourseVideo> list = courseVideoMapper.select(courseVideo);
        PageInfo<CourseVideo> pageInfo = new PageInfo<CourseVideo>(list);
        Map<String,Object> map = new HashMap<>();
        map.put("total", pageInfo.getTotal());
        map.put("rows", pageInfo.getList());
        map.put("sizes", pageInfo.getSize());
        return map;
    }
}

